package com.bawei.mdm2207alast.mine

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import coil.compose.AsyncImage
import com.bawei.mdm2207alast.R
import com.bawei.mdm2207alast.common.UserCard
import com.bawei.mdm2207alast.route.RouteConfig
import com.blankj.utilcode.util.ToastUtils
import com.tencent.mmkv.MMKV

/**
 * 作者：赵亮
 * 时间：2024/12/16 14:33
 * 功能：
 */
@Composable
fun MinePage(navController: NavController = rememberNavController()) {

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(start = 15.dp, end = 15.dp, top = 40.dp)
    ) {

        Text(text = "我的", fontSize = 22.sp)
        Spacer(modifier = Modifier.height(10.dp))
        val mmkv = MMKV.defaultMMKV()
        // 角色 1.员工 2.经理
        var role by remember {
            mutableStateOf(mmkv.decodeInt("role", 0))
        }
        UserCard(navController = navController, mmkv = mmkv)

        // 用户操作功能菜单
        Spacer(modifier = Modifier.height(10.dp))
        if (role != 0) {
            Card(
                elevation = CardDefaults.cardElevation(10.dp),
                modifier = Modifier.fillMaxWidth(),
                colors = CardDefaults.cardColors(containerColor = Color.White),
                border = BorderStroke(1.dp, color = Color.Black)
            ) {
                Row(modifier = Modifier.padding(10.dp)) {
                    Column(modifier = Modifier.clickable {
                        // 跳转到请假列表页面
                        navController.navigate(RouteConfig.ASK_LIST_PAGE)
                    }, horizontalAlignment = Alignment.CenterHorizontally) {
                        Image(
                            painter = painterResource(id = R.drawable.qj),
                            contentDescription = null
                        )
                        Text(text = "请假")
                    }
                    Spacer(modifier = Modifier.width(10.dp))
                    if (role == 2) {
                        Column(modifier = Modifier.clickable {
                            navController.navigate(RouteConfig.ASK_APPROVE_LIST)
                        }, horizontalAlignment = Alignment.CenterHorizontally) {
                            Image(
                                painter = painterResource(id = R.drawable.sp),
                                contentDescription = null
                            )
                            Text(text = "审批")
                        }
                    }
                }
            }
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun MinePagePreview() {
    MinePage()
}

